package samples.spring;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * BeanPostProcessor 接口会应用于所有Bean实例化时进行回调, 与InitializingBean不同
 *
 * @author wangyuchuan
 * @date 2018/1/9
 * @see BeanPostProcessor
 * @see org.springframework.beans.factory.InitializingBean
 */
public class PostProcessorBean implements BeanPostProcessor {
    public static final Logger log = LoggerFactory.getLogger(PostProcessorBean.class);

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        log.info("Spring回调BeanPostProcessor's postProcessBeforeInitialization method invoked: {}", beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        log.info("Spring回调BeanPostProcessor's postProcessAfterInitialization method invoked: {}", beanName);
        return bean;
    }
}
